package net.zoneland.knowledge.controller.util;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.io.Serializable;

/**
 * 选人控件选出来的结果对象。
 */
public class UserSelectItem implements Serializable {

    private static final long serialVersionUID = 1;

    /**
     * 用户uid。
     */
    private String uid;

    /**
     * 用户姓名。
     */
    private String name;

    /**
     * 所在组织简称。
     */
    private String orgShortName;

    /**
     * 是否根据查询组织获得。
     */
    private boolean queryByOrg;

    public UserSelectItem(){}

    private UserSelectItem(Builder builder) {
        this.uid = builder.uid;
        this.name = builder.name;
        this.orgShortName = builder.orgShortName;
        this.queryByOrg = builder.queryByOrg;
    }

    public static Builder newUserSelectItem() {
        return new Builder();
    }

    /**
     * Gets the value of uid.
     *
     * @return the value of uid
     */
    public String getUid() {
        return uid;
    }

    /**
     * Sets the uid.
     *
     * @param uid uid
     */
    public void setUid(final String uid) {
        this.uid = uid;
    }

    /**
     * Gets the value of name.
     *
     * @return the value of name
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name.
     *
     * @param name name
     */
    public void setName(final String name) {
        this.name = name;
    }

    /**
     * Gets the value of orgShortName.
     *
     * @return the value of orgShortName
     */
    public String getOrgShortName() {
        return orgShortName;
    }

    /**
     * Sets the orgShortName.
     *
     * @param orgShortName orgShortName
     */
    public void setOrgShortName(final String orgShortName) {
        this.orgShortName = orgShortName;
    }

    /**
     * 是否通过组织选择。
     * @return 是否通过组织选择
     */
    public boolean isQueryByOrg() {
        return queryByOrg;
    }

    /**
     * 设置是否通过组织选择。
     * @param queryByOrg 是否通过组织选择
     */
    public void setQueryByOrg(final boolean queryByOrg) {
        this.queryByOrg = queryByOrg;
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        final UserSelectItem that = (UserSelectItem) o;

        return new EqualsBuilder().append(queryByOrg, that.queryByOrg).append(uid, that.uid)
                .append(name, that.name).append(orgShortName, that.orgShortName).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37).append(uid).append(name)
                .append(orgShortName).append(queryByOrg).toHashCode();
    }

    public static final class Builder {
        private String uid;
        private String name;
        private String orgShortName;
        private boolean queryByOrg;

        private Builder() {
        }

        public UserSelectItem build() {
            return new UserSelectItem(this);
        }

        public Builder uid(String uid) {
            this.uid = uid;
            return this;
        }

        public Builder name(String name) {
            this.name = name;
            return this;
        }

        public Builder orgShortName(String orgShortName) {
            this.orgShortName = orgShortName;
            return this;
        }

        public Builder queryByOrg(boolean queryByOrg) {
            this.queryByOrg = queryByOrg;
            return this;
        }
    }
}
